package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.HotArticleService;
import com.heima.common.constants.HotArticleConstants;
import com.heima.model.message.vos.ArticleVisitStreamMess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * 热点文章实时计算监听类
 */
@Component
public class HotArticleListener {

    @Autowired
    private HotArticleService hotArticleService;
    /**
     * 监听的是流式处理之后的topic
     * @param message
     */
    @KafkaListener(topics = HotArticleConstants.HOT_ARTICLE_INCR_HANDLE_TOPIC)
    public void getMessage(String message){
        //1.转对象
        ArticleVisitStreamMess mess = JSON.parseObject(message, ArticleVisitStreamMess.class);
        //2.调接口
        hotArticleService.updateScore(mess);
    }
}
